package com.hualan.zhsq.service.impl.property;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hualan.zhsq.entity.property.AccessRecord;
import com.hualan.zhsq.mapper.property.AccessRecordMapper;
import com.hualan.zhsq.service.property.AccessRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName AccessRecordServiceImpl
 * @Description 访问记录serviceImpl
 * @Author ZheRan
 * @Date 2025年08月04日 下午7:46
 * @Version 1.0
 */
@Service("accessRecordService")
public class AccessRecordServiceImpl implements AccessRecordService {

    @Autowired
    private AccessRecordMapper accessRecordMapper;
    @Override
    public int add(AccessRecord entity) {
        return accessRecordMapper.insert(entity);
    }

    @Override
    public int edit(AccessRecord entity) {
        return accessRecordMapper.updateById(entity);
    }

    @Override
    public int remove(Integer id) {
        return accessRecordMapper.deleteById(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return accessRecordMapper.deleteBatchIds(List.of(ids));
    }

    @Override
    public List<AccessRecord> find() {
        return accessRecordMapper.selectList(null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, AccessRecord entity) {
        Page<AccessRecord> page = new Page(pageNum, pageSize);
        Page<AccessRecord> accessRecordPage = accessRecordMapper.selectPage(page, null);
        Map<String, Object> map = new HashMap<>();
        map.put("list",accessRecordPage.getRecords());
        map.put("total", accessRecordPage.getTotal());
        map.put("size", accessRecordPage.getSize());
        return map;
    }

    @Override
    public AccessRecord findById(Integer id) {
        return accessRecordMapper.selectById(id);
    }
}
